test(Lazy): cover initial render, navigation loading, and reactive each#7
Merged
Merged
Conversation
Adds tests/Lazy.test.tsx with 14 cases focused on the TV-app use case of a Column of LazyRows: - Initial render: sync mounts upCount synchronously; !sync ramps up via the 16ms setTimeout chain; each shorter than upCount caps the visible count; falsy each renders nothing. - Navigation-driven loading: ArrowRight at the buffer edge mounts the next item; mounting stops at each.length; staying inside the buffer does not trigger a mount. - Column of LazyRows (the real TV layout): multiple rows render their upCounts independently; loading items in one row leaves siblings untouched; moving up/down between rows preserves each row's loaded count. - LazyColumn: ArrowDown drives vertical loading. - Reactive each: shrinking past selected keeps focus inside a valid range; growing each.length does not auto-mount beyond offset. - Cleanup: unmounting mid-preload-ramp produces no errors. Tests pass against this branch and (with no further changes) against main, validating that the prior correctness PR preserved behavior. Also fixes a latent module-init bug in VirtualGrid that vitest exposed: VirtualGrid.tsx had `const columnScroll = lngp.withScrolling(false)` at module top level, reading from the `@solidtv/solid/primitives` barrel that was still mid-construction (withScrolling is exported later in the barrel's index). Production bundlers reorder the deps and hide the cycle; vitest's vite-node SSR loader does not, so the barrel access returned undefined and threw on call. The fix uses the pre-built `scrollColumn` constant already exported from `./utils/withScrolling.js` — same direct-import pattern Row.tsx uses for `scrollRow`. Deduplicates an identical `withScrolling(false)` call and removes the module-init-time barrel dependency. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
556c8c1 to
226afba
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on top of #6.
Summary
Two changes:
tests/Lazy.test.tsx— 14 cases focused on the TV-app use case of aColumncontaining manyLazyRows.src/primitives/VirtualGrid.tsx— fixes a latent module-init bug that vitest exposed.The VirtualGrid fix
VirtualGrid.tsxhad this at module top level:When the barrel is evaluated, exports populate in declaration order.
VirtualGridis exported beforewithScrollinginprimitives/index.ts, so when VirtualGrid's module-init code runs,lngp.withScrollingis stillundefined. Production bundlers reorder the deps and hide the cycle; vitest's vite-node SSR loader doesn't, so the barrel access returnsundefinedand throws on call.Fix uses the pre-built
scrollColumnconstant already exported from./utils/withScrolling.js— same direct-import patternRow.tsxuses forscrollRow. As a bonus, deduplicates an identicalwithScrolling(false)call.With this fix, the barrel loads cleanly under vitest, so
Lazy.tsxdoes not need its own import workaround. The earlier draft of this PR refactored Lazy's imports; that's been reverted in favor of the real fix.Test coverage
Initial render
sync=truemountsupCountitems synchronously!syncramps up toupCountover time (verifies the 16ms setTimeout chain)each.lengthwhen shorter thanupCounteachisnull/falseNavigation-driven loading
each.lengthColumn of LazyRows (the real TV shape)
LazyRows render theirupCounts independentlyLazyColumn
Reactive
eachselectedkeeps focus inside a valid index rangeeach.lengthdoes not auto-mount beyond the current offsetCleanup
Test plan
npm run tsc— cleannpm test— 134/134 (120 prior + 14 new)import * as lngp from '@solidtv/solid/primitives'now succeeds under vitest🤖 Generated with Claude Code